package com.gjq.sensitive.template;

import com.gjq.sensitive.SensitiveFilter;

/**
 * 过滤词模板方法
 * @Author: Gjq
 * @Date: 2019/7/3 0003 下午 1:53
 */
public class SensitiveTemplate {
    class Match{
        //最小匹配规则
        public static final int MIN_MATCH_TYPE = 1;
        //最大匹配规则
        public static final int MAX_MATCH_TYPE = 2;
    }
    private final SensitiveFilter sensitiveFilter;
    public SensitiveTemplate(SensitiveFilter sensitiveFilter) {
        this.sensitiveFilter = sensitiveFilter;
    }
    /**
     * 是否包含敏感词
     * @param text
     * @return
     */
    public Boolean isSensitiveCode(String text){
        return sensitiveFilter.isContaintSensitiveWord(text,Match.MIN_MATCH_TYPE);
    }

    /**
     * 如存在敏感词则返回替换的文本*
     * @param text
     * @return
     */
    public String replaceSensitiveWord(String text){
        return sensitiveFilter.replaceSensitiveWord(text,Match.MIN_MATCH_TYPE,"*");
    }
}
